package filter;

import org.apache.commons.lang3.StringUtils;

import javax.servlet.*;
import javax.xml.crypto.dsig.spec.XPathType;
import java.io.IOException;

public class CharactorFilter implements Filter {
    private  String encoding="UTF-8";
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        String encoding =filterConfig.getInitParameter("encoding");
        if (StringUtils.isNotBlank(encoding)){
            this.encoding=encoding;
        }
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding(encoding);
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
